﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Fjaspx.Common;
using Fjaspx.DB;
namespace Fjaspx.UI.Web.Admin.Article
{
    public partial class ArticleAdd : System.Web.UI.Page
    {
        public string channelId_temp = "";
        public string classId_temp = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.channelId_temp = Request["channelID"];
                this.classId_temp = Request["Class_ID"];
                this.classId_droplist.Attributes.Add("onchange", "onChangeVal()");
                this.channelId_droplist.Attributes.Add("onchange", "load(this.options[this.selectedIndex].value)");
                this.hits_text.Attributes.Add("onblur", "isNumber(this.value)");
                this.addArtBtn.Attributes.Add("onclick", "return checkVal();");
                BindAllData(this.channelId_temp, this.classId_temp);
            }
        }
        #region 数据初始绑定
        public void BindAllData(string _channelId, string _classId)
        {
            string str = "SELECT Count(0) FROM Fjaspx_Channel";
            int channelList = int.Parse(DbHelperSQL.GetSingle(str).ToString());
            if (channelList == 0)
            {
                JsMsg.ShowAndRedirect(this.Page, "对不起!目前暂无任何频道存在，请先添加频道后再添加文章！", "InforChannel/ChannelAnd.aspx");
            }
            else
            {
                BindDropDownList_Channel();
                if (_channelId != "")
                {
                    channelId_droplist.SelectedValue = _channelId;
                }
            }
            artFrom_text.Text = "福建ASP.NET技术专业站";
            hits_text.Text = "100";
            artUrl_text.Text = "www.fjaspx.com";
            createDate_text.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            modiDate_text.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            this.author_text.Text = "福建ASP.NET技术专业站";
            this.inputerl_text.Text = "系统管理员";

        }
        #endregion

        #region 绑定频道数据
        public void BindDropDownList_Channel()
        {
            try
            {
                channelId_droplist.DataSource = new Fjaspx.Sys.Bll.Fjaspx_Channel().GetList("IsShow=1");
                channelId_droplist.DataTextField = "ChannelName";
                channelId_droplist.DataValueField = "OrderId";
                channelId_droplist.DataBind();
            }
            catch { }
        }
        #endregion

        #region   添加文章
        protected void addArtBtn_Click(object sender, EventArgs e)
        {

            if (FCKeditor1.Value == "")
            {
                JsMsg.Alert("请输入文章内容！");
            }
            if (channelId_droplistVal.Value != "" && classId_droplistVal.Value != "" && artDes_text.Text != "" && artKeyword_text.Text != "" && FCKeditor1.Value != "")
            {
                int result = 0;
                Fjaspx.Sys.Model.Fjaspx_Article model = new Fjaspx.Sys.Model.Fjaspx_Article();
                model.Area = this.ClassID.Value;
                model.ArtAdmin = this.inputerl_text.Text;
                model.ArtAuthor = this.author_text.Text;
                model.ArtColor = "#FFFFFF";
                model.ArtContent = FCKeditor1.Value;
                model.ArtCount = 0;
                model.ArtDate = Convert.ToDateTime(createDate_text.Text);
                model.ArtHome = artFrom_text.Text;
                model.ArtInfo = artDes_text.Text;
                model.ArtKeyword = artKeyword_text.Text;
                model.ArtReview = "NULL";
                model.ArtReviewcount = int.Parse(hits_text.Text);
                model.ArtTitle = title_text.Text;
                model.ArtTitle2 = subtitle_text.Text;
                model.ArtUrl = artUrl_text.Text;
                model.CatId = int.Parse(classId_droplistVal.Value);
                model.ChannelId = int.Parse(channelId_droplistVal.Value);
                model.Images = this.picPath.Text;
                if (isPic_text.Checked)
                    model.IsImg = 1;
                else model.IsImg = 0;

                if (isTop_cbox.Checked)
                    model.IsTop = 1;
                else
                    model.IsTop = 0;
                if (stateNow_lable.Checked)
                    model.Passed = 1;
                else model.Passed = 0;
                if (isTj_cbox.Checked)
                    model.Recommend = 1;
                else
                    model.Recommend = 0;
                model.UpdateDate = Convert.ToDateTime(modiDate_text.Text);
                result = new Fjaspx.Sys.Bll.Fjaspx_Article().Add(model);
                if (result != 1)
                    JsMsg.MsgBoxRedrect("添加文章成功！", "ArticleManage.aspx", this.Page);
                else
                    JsMsg.MsgBoxRedrect("出现异常！添加文章失败！", "ArticleManage.aspx", this.Page);
            }
            else
            {
                JsMsg.Alert("请选择类别");
            }
        }
        #endregion
    }
}